﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using PlugNT.Custom;
using PlugNT.Cms.Core;
using PlugNT.Cms.Model;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_Create
{

    public partial class BindTemplet : AdminPage
    {
        private Templet curTemplet = new Templet();
        private string currpostfix = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            if (!IsPostBack)
            {
                currpostfix = (Request.QueryString["currpostfix"] == null) ? WebConfig.TablePostfix : Request.QueryString["currpostfix"].Trim();
                BindData();
            }
        }

        #region 数据绑定
        private void BindData()
        {

            DataTable dt = curTemplet.GetBingList(currpostfix);  //WebConfig.TablePostfix
            this.rptStaticTemplets.DataSource = dt.DefaultView;
            this.rptStaticTemplets.DataBind();

            if (WebConfig.AspxTemplets != null)
            {
                StringBuilder sb = new StringBuilder();
                foreach (KeyValuePair<string, string> keyValue in WebConfig.AspxTemplets)
                {
                    sb.AppendLine("<tr class=\"td_on\" onmouseover=\"this.className='td_off'\" onmouseout=\"this.className='td_on'\">");
                    string[] tmpkv = keyValue.Value.Split('|');
                    sb.AppendLine("<td>" + keyValue.Key + "</td>");
                    sb.AppendLine("<td><div style=\" overflow:hidden; text-overflow: ellipsis; width: 420px;\" title=\"" + tmpkv[0] + "\">" + tmpkv[0] + "</td>");

                    if (tmpkv.Length > 1 && tmpkv[1].Trim() == "true")
                    {
                        sb.AppendLine("<td align=\"center\"><b>√</b></td>");
                    }
                    else
                    {
                        sb.AppendLine("<td align=\"center\"><b>×</b></td>");
                    }

                    sb.AppendLine("<td align=\"center\"><a href='EditDynamicTemplet.aspx?t=edit&name=" + keyValue.Key + "&path="+keyValue.Value+"'>修改</a> &nbsp;");
                    sb.AppendLine("<a href='EditDynamicTemplet.aspx?t=delete&name=" + keyValue.Key + "' onclick=\"return CheckSubmit('删除');\">删除</a></td>");
                    sb.AppendLine("</tr>");
                }
                litDynamicTemplets.Text = sb.ToString();
            }
            else
            {
                litDynamicTemplets.Text = "null";
            }

        }
        #endregion


        #region 显示数据处理
        protected void rptStaticTemplets_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Literal LitFirst = (Literal)e.Item.FindControl("LitFirst");
                Label LabClassNm = (Label)e.Item.FindControl("LabClassNm");
                Literal litCreateSiteMap = (Literal)e.Item.FindControl("litCreateSiteMap");

                string LitStyle = "<span style=\" width:{0}px; display:block; float:left; text-align:right; vertical-align:middle; line-height:25px; height:25px;\">{1}{2}</span>";
                string LitImg1 = "<img src=../images/openfolder.gif align=absmiddle />";
                string LitImg2 = "<img src=../images/folder.gif align=absmiddle />";
                string LitImg3 = "<img src=../images/t.gif align=absmiddle />";

                DataRowView drv = (DataRowView)e.Item.DataItem;
                int clsListLen = Convert.ToInt32(drv["clslistlen"]);
                if (clsListLen == 1)
                {
                    LabClassNm.Font.Bold = true;
                    LitFirst.Text = LitImg1;
                }
                else
                {
                    LitFirst.Text = string.Format(LitStyle, clsListLen * 20, LitImg3, LitImg2);
                }
                if (drv["ismap"].ToString() == "1")
                {
                    litCreateSiteMap.Text = "<b>√</b>";
                }
                else
                {
                    litCreateSiteMap.Text = "<b>×</b>";
                }

            }
        }

        #endregion

    }
}
